﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class CheckEnterpriseInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        public void BindData()
        {
            if (Request.QueryString["psid"] != "" && Request.QueryString["psid"] != null)
            {
                string comPS_Id = Request.QueryString["psid"].ToString();
                this.AreaName.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetAreasByComId(comPS_Id);
                this.lblSort.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyType(comPS_Id);
                HZ.DrugTrade.Model.CompanyInfo com = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyInfoByID(comPS_Id);
                this.lblAddress.Text = com.Address;//联系地址
                this.lbladulterant.Text = com.Adulterant;//两年内有无假药记录
                this.lblAuthor.Text = com.Author;//被授权人
                this.lblAuthorCell.Text = com.AuthorCell;//被授权人手机
                this.lblCellPhone.Text = com.CellNo;//联系人手机
                this.lblComCode.Text = com.Comcode;//企业代码证号
                this.lblComEndTime.Text = Constants.ReturnTime(com.ComEndtime);//企业代码证有效期
                this.lblComFax.Text = com.Fax;//企业传真
                this.lblComName.Text = com.CompanyName;//企业名称
                this.lblComTel.Text = com.TelNo;//企业联系电话
                this.lbldevious.Text = com.Devious;//是否有不正当行为
                this.lblEmail.Text = com.Email;//电子信箱
                this.lblPermission.Text = com.Permission;//营业执照号
                this.lblPermissionDate.Text = Constants.ReturnTime(com.PermissionDate);//营业执照期限
                this.lblPermissionCheckDate.Text = Constants.ReturnTime(com.PermissionCheckDate);//营业执照年检日期
                this.lblPermitLicence.Text = com.BusinessCertificate;//生产或经营许可证号
                this.lblPermitLicenceEndTime.Text = Constants.ReturnTime(com.BusinessCertificateDate);//许可证有效期
                this.lblPermitLicenceRange.Text = com.BusinessRange;//经营范围
                this.lblPostCode.Text = com.PostCode;//邮政编码
                this.lblRegisterAddress.Text = com.RegistAddress;//企业注册地址
                this.lblRegisterFund.Text = com.RegisterFund.ToString();//企业注册资金
                this.lblStoreHouseAddress.Text = com.StoreHouseAddress;//仓库地址
                this.lblLawerPerson.Text = com.LayMan;//法人
                this.lblContactPerson.Text = com.ContactPerson;//企业联系人
                this.lblRemarks.Text = com.Remarks;//备注
                this.lblUserCode.Text = comPS_Id;//企业用户编号
                
           
                if (CurrentAccount.GetUser().UserID.ToUpper().Contains("ZBZX"))
                {
                    string status = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select checkstatus from TB_PSselectArea where companyPS_Id='" + comPS_Id + "' and areaid='"+Request.QueryString["areaid"].ToString()+"'").ToString();
                    if (status == "1")
                    {
                        txtOtherReason.Text = "";
                    }
                    else
                    {
                        txtOtherReason.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select reason from TB_PSselectArea where companyPS_Id='" + comPS_Id + "' and areaid='" + Request.QueryString["areaid"].ToString() + "'").ToString();
                    }
                }
                else
                {
                    string status = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select checkstatus from TB_PSselectArea where companyPS_Id='" + comPS_Id + "' and areaid=(select areaid from TB_ManageOrg where ManageOrgID='" + CurrentAccount.GetUser().Org.OrgID + "')").ToString();
                    if (status == "1")
                    {
                        txtOtherReason.Text = "";
                    }
                    else
                    {
                        txtOtherReason.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select reason from TB_PSselectArea where companyPS_Id='" + comPS_Id + "' and areaid=(select areaid from TB_ManageOrg where ManageOrgID='" + CurrentAccount.GetUser().Org.OrgID + "')").ToString();
                    }
                    this.AreaName.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select ManageOrgName from TB_ManageOrg where ManageOrgID='" + CurrentAccount.GetUser().Org.OrgID + "'").ToString();
                }
                
                
            }
            else
            {
                this.Controls.Add(new LiteralControl("<script>alert('参数错误')</script>"));
                Response.Redirect("../UserLogin.aspx");
            }
        }

        //审核通过
        protected void btnPass_Click(object sender, EventArgs e)
        {
            string userId = CurrentAccount.GetUser().UserID;
            HZ.DrugTrade.Model.PSSelectArea ps = new HZ.DrugTrade.Model.PSSelectArea();
            ps.CompanyPS_Id = Request.QueryString["psid"].ToString();
            ps.Reason = txtOtherReason.Text;
            ps.ReasonByZbzx = txtOtherReason.Text;
            if (Request.QueryString["areaid"]!=null)
            {
                ps.AreaId = Request.QueryString["areaid"].ToString();
            }
            
            bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckEnterpriseInfo(ps, 1, userId);
            if (flag)
            {
                HZ.Web.MessageBox.Show("审核成功");
                BindData();
            }
            else
            {
                HZ.Web.MessageBox.Show("审核失败");
            }
        }
        //审核不通过
        protected void btnUnPass_Click(object sender, EventArgs e)
        {
            if (txtOtherReason.Text == "")
            {
                HZ.Web.MessageBox.Show("请填写不通过理由");
                return;
            }
            else
            {
                string userId = CurrentAccount.GetUser().UserID;
                HZ.DrugTrade.Model.PSSelectArea ps = new HZ.DrugTrade.Model.PSSelectArea();
                ps.CompanyPS_Id = Request.QueryString["psid"].ToString();
                ps.Reason = txtOtherReason.Text;
                ps.ReasonByZbzx = txtOtherReason.Text;
                if (Request.QueryString["areaid"] != null)
                {
                    ps.AreaId = Request.QueryString["areaid"].ToString();
                }
                bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckEnterpriseInfo(ps, 2, userId);
                if (flag)
                {
                    HZ.Web.MessageBox.Show("审核成功");
                    BindData();
                }
                else
                {
                    HZ.Web.MessageBox.Show("审核失败");
                }
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("RelationCheckAreaByMS.aspx");
        }
    }
}
